package com.ruoyi.basebill.service.impl;

import java.util.List;

import com.ruoyi.basebill.domain.WfzCwsgtzs;
import com.ruoyi.basebill.domain.WfzCwsgtzsentry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.basebill.mapper.WfzCwsgtzsMapper;

import com.ruoyi.basebill.service.IWfzCwsgtzsService;

/**
 * 手工调整数据Service业务层处理
 * 
 * @author lianxiaolong
 * @date 2022-12-17
 */
@Service
public class WfzCwsgtzsServiceImpl implements IWfzCwsgtzsService 
{
    @Autowired
    private WfzCwsgtzsMapper wfzCwsgtzsMapper;

    /**
     * 查询手工调整数据
     * 
     * @param fid 手工调整数据主键
     * @return 手工调整数据
     */
    @Override
    public WfzCwsgtzs selectWfzCwsgtzsByFid(Long fid)
    {
        return wfzCwsgtzsMapper.selectWfzCwsgtzsByFid(fid);
    }

    /**
     * 查询手工调整数据列表
     * 
     * @param wfzCwsgtzs 手工调整数据
     * @return 手工调整数据
     */
    @Override
    public List<WfzCwsgtzs> selectWfzCwsgtzsList(WfzCwsgtzs wfzCwsgtzs)
    {
        return wfzCwsgtzsMapper.selectWfzCwsgtzsList(wfzCwsgtzs);
    }

    /**
     * 新增手工调整数据
     * 
     * @param wfzCwsgtzs 手工调整数据
     * @return 结果
     */
    @Transactional
    @Override
    public int insertWfzCwsgtzs(WfzCwsgtzs wfzCwsgtzs)
    {
        int rows = wfzCwsgtzsMapper.insertWfzCwsgtzs(wfzCwsgtzs);
        insertWfzCwsgtzsentry(wfzCwsgtzs);
        return rows;
    }

    /**
     * 修改手工调整数据
     * 
     * @param wfzCwsgtzs 手工调整数据
     * @return 结果
     */
    @Transactional
    @Override
    public int updateWfzCwsgtzs(WfzCwsgtzs wfzCwsgtzs)
    {
        wfzCwsgtzsMapper.deleteWfzCwsgtzsentryByFparentid(wfzCwsgtzs.getFid());
        insertWfzCwsgtzsentry(wfzCwsgtzs);
        return wfzCwsgtzsMapper.updateWfzCwsgtzs(wfzCwsgtzs);
    }

    /**
     * 批量删除手工调整数据
     * 
     * @param fids 需要删除的手工调整数据主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteWfzCwsgtzsByFids(Long[] fids)
    {
        wfzCwsgtzsMapper.deleteWfzCwsgtzsentryByFparentids(fids);
        return wfzCwsgtzsMapper.deleteWfzCwsgtzsByFids(fids);
    }

    /**
     * 删除手工调整数据信息
     * 
     * @param fid 手工调整数据主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteWfzCwsgtzsByFid(Long fid)
    {
        wfzCwsgtzsMapper.deleteWfzCwsgtzsentryByFparentid(fid);
        return wfzCwsgtzsMapper.deleteWfzCwsgtzsByFid(fid);
    }

    /**
     * 新增手工调整数据分录信息
     * 
     * @param wfzCwsgtzs 手工调整数据对象
     */
    public void insertWfzCwsgtzsentry(WfzCwsgtzs wfzCwsgtzs)
    {
        List<WfzCwsgtzsentry> wfzCwsgtzsentryList = wfzCwsgtzs.getWfzCwsgtzsentryList();
        Long fid = wfzCwsgtzs.getFid();
        if (StringUtils.isNotNull(wfzCwsgtzsentryList))
        {
            List<WfzCwsgtzsentry> list = new ArrayList<WfzCwsgtzsentry>();
            for (WfzCwsgtzsentry wfzCwsgtzsentry : wfzCwsgtzsentryList)
            {
                wfzCwsgtzsentry.setFparentid(fid);
                list.add(wfzCwsgtzsentry);
            }
            if (list.size() > 0)
            {
                wfzCwsgtzsMapper.batchWfzCwsgtzsentry(list);
            }
        }
    }
}
